package cz.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @Title: HibernateUtil
 * @Description: cz.utils
 * @Auther: Jason.Song
 * @Version: 1.0
 *
 * 目的:抽取出sessionfactory,并且可以返回一个session对象
 *
 */
public class HibernateUtil {
    private  static final Configuration configuration;
    private static final SessionFactory sessionFactory;

    static{
        configuration = new Configuration().configure();
        sessionFactory = configuration.buildSessionFactory();
    }

    public static Session openSession() {
        return sessionFactory.openSession();
    }

    //必须要在Hibernate的核心配置文件中配置session的绑定才可以使用
    public static Session getCurrentSession() {
        return sessionFactory.getCurrentSession();
    }

}
